<?php

namespace App\Http\Controllers;

use App\Hydrators\AbsenceHydrator;
use App\Models\Absence;
use App\Models\User;
use App\Repositories\Absence\AbsenceFilter;
use App\Repositories\Absence\AbsenceRepository;
use App\Repositories\User\UserFilter;
use App\Repositories\User\UserRepository;
use App\Transformers\AbsenceTransformer;
use App\Transformers\UserTransformer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class AbsenceController extends Controller
{
    public function index(AbsenceRepository $absenceRepository, Request $request)
    {
        $paginator = $absenceRepository->getPaginator(new AbsenceFilter($request));
        return $this->response->paginator($paginator, new AbsenceTransformer());
    }

    public function show($id)
    {
        $obj = Absence::find($id)->with('users')->get();
        return $this->response->item($obj, new AbsenceTransformer());
    }

    public function store()
    {
        $AbsenceSturct = $this->hydrate(new Absence(), new AbsenceHydrator());
        return $this->response()->created(null, $AbsenceSturct);
    }

    public function destroy($id)
    {
        Absence::destroy($id);
        return $this->response->noContent();
    }
}


